﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


using System.Runtime.InteropServices;
using System.IO;
namespace EQual.MainModule.Employees.DetailsViews
{
    /// <summary>
    /// Interaction logic for DocumentsDetailedControl.xaml
    /// </summary>
    public partial class EmployeeDetailedControl : UserControl
    {
        public EmployeeDetailedControl()
        {
            InitializeComponent();
        }

        #region IDocumentDetailedControl Members

        public void DispalyDocumentDetails(DataAccesLayer.Employee empl)
        {

            ActiveItem = empl;
            
        }

        //private DataAccesLayer.Employee  ;

        public DataAccesLayer.Employee ActiveItem
        {
            get
            {
                return DataContext  as DataAccesLayer .Employee ;
            }
            set
            {
                DataContext  = value  ;
            }
        }

        #endregion

        private void image1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            UploadImage();
        }

        private void UploadImage()
        {
            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filepa = dlg.FileName;

                FileStream fs = new FileStream(filepa, FileMode.OpenOrCreate, FileAccess.Read);

                byte[] MyData = new byte[fs.Length];
                fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));

                fs.Close();

                char MyChar = '\\';
                string[] hg = filepa.Split(MyChar);
                string h = hg[hg.Length - 1];

                ActiveItem.Picture = new System.Data.Linq.Binary(MyData);

                new DataAccesLayer.EQualDataLayerFactory().UpdateDataBase();
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            UploadImage();
            this.UpdateLayout();
        }
    }
}
